package dao

import (
	"chatting/config"
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
	"log"
)

var gdb *gorm.DB

func init() {
	var err error
	cfg := config.MysqlConfig
	gdb, err = gorm.Open(mysql.Open(fmt.Sprintf("%s:%s@tcp(%s)/%s?parseTime=True", cfg.Username, cfg.Password, cfg.Addr, cfg.Database)), &gorm.Config{
		Logger: logger.Default.LogMode(logger.Info),
	})
	if err != nil {
		log.Println(err)
		return
	}
	fmt.Println(gdb.CreateBatchSize)
	//gdb.AutoMigrate(&model.UserInfo{}, &model.Game{})
	//gdb.AutoMigrate(&model.Way{}, &model.Game{})
}

func AutoMigrate(in interface{}) {
	gdb.AutoMigrate(in)
}
